<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-layer-content .layui-table{margin: 0;}
</style>
<body>

    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form" lay-filter="searchForm">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">日期：</label>
                    <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                        <div class="layui-input-inline" style="margin-right:10px">
                            <input type="text" autocomplete="off" name="start_date" id="start_date" class="layui-input"
                                placeholder="开始日期">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" name="end_date" id="end_date" class="layui-input"
                                placeholder="结束日期">
                        </div>
                    </div>
                </div>

                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>

        <!-- <blockquote class="layui-elem-quote">近30日数据统计（不含当日）</blockquote> -->
        <table id="history" lay-filter="history"></table>
    </div>
    <script>
        let totalObj = {}
        let link_id = GetQueryString('link_id')
        let params = {
            elem: '#history'
            , toolbar: true
            , url: '/cps/order/data?link_id=' + link_id //数据接口
            , id: 'history'
            , page: true
            , totalRow:true
            , cols: [[ //表头
                {field: 'date', title: '日期', align:'center' ,totalRowText: '总合计：'}
                , { field: 'activation_user_num', title: '激活用户数', align:'center' }
                , { field: 'cost', title: '花费', align:'center' }
                , { field: 'actual_cost', title: '实际花费', align:'center' }
                , { field: 'new_user_number', title: '新充人数', align:'center' }
                , { field: 'new_recharge_number', title: '新充笔数', align:'center' }
                , { field: 'current_recharge', title: '新充金额', align:'center' }
                , { field: 'conversion_number', title: '充值人数', align:'center' }
                , { field: 'recharge_number', title: '充值笔数', align:'center' }
                , { field: 'total_recharge', title: '累计充值', align:'center' }
            ]],
            customTotal:function(){
                let that = this;
                layui.use('form', function () {
                    getTotal('/cps/order/getHistoryDataSum',totalObj,{link_id}).then(val=>{
                        totalObj = val
                    })
                });
            },
            done:function(){
                setPrice(totalObj)
            }
        }
        tableList(params)

        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //日期范围
            laydate.render({
                elem: '#time'
                , range: ['#start_date', '#end_date']
                ,format: 'yyyy-MM-dd'
            });
        })

        function setPrice(totalObj){
            $('.layui-table-total td[data-field="activation_user_num"] .layui-table-cell').text(totalObj.activation_user_num);//激活用户数
            $('.layui-table-total td[data-field="cost"] .layui-table-cell').text(totalObj.cost);//花费
            $('.layui-table-total td[data-field="actual_cost"] .layui-table-cell').text(totalObj.actual_cost);//实际花费
            $('.layui-table-total td[data-field="new_recharge_number"] .layui-table-cell').text(totalObj.new_recharge_number);//新充值笔数
            $('.layui-table-total td[data-field="new_user_number"] .layui-table-cell').text(totalObj.new_user_number);//新充人数
            $('.layui-table-total td[data-field="current_recharge"] .layui-table-cell').text(totalObj.current_recharge);//新充金额
            $('.layui-table-total td[data-field="conversion_number"] .layui-table-cell').text(totalObj.conversion_number);//充值人数
            $('.layui-table-total td[data-field="recharge_number"] .layui-table-cell').text(totalObj.recharge_number);//充值笔数
            $('.layui-table-total td[data-field="total_recharge"] .layui-table-cell').text(totalObj.total_recharge);//累计充值
        }
    </script>
</body>

</html>